﻿using Sustainalytics.ESGRatings.DataContract.ESG;
using System;
using System.Linq;
using Sustainalytics.Entities.ESGRatings;
using System.Configuration;

namespace Sustainalytics.ESGComputing.BenchmarkTest
{
    class Program
    {
        static void Main(string[] args)
        {
            /*var options = new ESGRatingsOptionsDto()
            {
                RefUnivId = new Guid("71f2972e-3153-4f83-ac6e-d82bd676481f"), //),"71f2972e-3153-4f83-ac6e-d82bd676481f"),
                MatrixId = new Guid("290a624d-a1bf-4298-b91d-2456223923d5"),//290a624d-a1bf-4298-b91d-2456223923d5
                IncludeAggregatedScores = true,
                IncludeIndWeightedScores = true,
                IncludeRatings = true,
                GroupBy = ComparativeGroupEnum.IndustryGroup,
                //TemplateType = TemplateTypeEnum.TypeA,
                //CompanyType = CompanyTypeEnum.Private,
                CompaniesIds = new List<Guid>() { new Guid("ff45686c-9e4d-4d4f-b920-962af834ef0a") }
            };*/
            //string url = "http://localhost:10280/esgcomputingserv/api/v1/esgcompute";

            string matrixId = ConfigurationManager.AppSettings["MatrixId"];
            string refUnivId = ConfigurationManager.AppSettings["RefUnivId"];
            string includeAggregatedScores = ConfigurationManager.AppSettings["IncludeAggregatedScores"];
            string includeIndWeightedScores = ConfigurationManager.AppSettings["IncludeIndWeightedScores"];
            string includeRatings = ConfigurationManager.AppSettings["IncludeRatings"];
            string groupBy = ConfigurationManager.AppSettings["groupBy"];
            string companiesIds = ConfigurationManager.AppSettings["companiesIds"];
            var compIds = companiesIds.Split(',').Select(s=>new Guid(s));

            var options = new ESGRatingsOptionsDto()
            {
                RefUnivId = new Guid(refUnivId),
                MatrixId = new Guid(matrixId),
                IncludeAggregatedScores = bool.Parse(includeAggregatedScores),
                IncludeIndWeightedScores = bool.Parse(includeIndWeightedScores),
                IncludeRatings = bool.Parse(includeRatings),
                GroupBy = (ComparativeGroupEnum)Enum.Parse(typeof(ComparativeGroupEnum), groupBy),
                //TemplateType = TemplateTypeEnum.TypeA,
                //CompanyType = CompanyTypeEnum.Private,
                CompaniesIds = compIds.ToList()
            };

            string url = ConfigurationManager.AppSettings["UrlToHit"];
            int nCount = int.Parse(ConfigurationManager.AppSettings["NoOfcalls"]);
            //for (int i = 1; i <= nCount; i++)
            {
                var benchmark = new ESGComputingBenchmark(url, options);
                double maxDuration = benchmark.Execute(nCount, true);
                Console.WriteLine("Max duration for {0} call(s) = {1}{2}", nCount, maxDuration, Environment.NewLine);
            }

            Console.WriteLine("Done!!!");
            Console.ReadLine();
        }
    }
}
